<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layuimini-main">

        <form class="layui-form" action="">
            <input type="hidden" name="id" value="{$id}">

            <div class="layui-form-item">
                <label class="layui-form-label">团队名称</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="{$team.title}" lay-verify="question" autocomplete="off" placeholder="请输入标题" class="layui-input iwidth" aria-disabled="true">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">团队领导</label>
                <div class="layui-input-block" style="display: flex">
                    <input type="text" name="" value="{$team.memberName}" autocomplete="off" placeholder="请输入标题" class="layui-input iwidth" disabled>
                    <button data-method="offset" type="button" data-type="auto" class="layui-btn layui-btn-sm  "  onclick='clickMember("{$team.member_code}")' style="margin-top: 4px;margin-left: 10px">查看</button>
                    <button data-method="offset" type="button" data-type="auto" class="layui-btn layui-btn-sm layui-btn-normal" onclick='clickReplace("{$team.member_code}")' id="" style="margin-top: 4px;margin-left: 10px">更换</button>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">团队人数</label>
                <div class="layui-input-block">
                    <input type="number"  value="{$team.team_num}"  autocomplete="off" readonly class="layui-input iwidth" >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">团队总收益</label>
                <div class="layui-input-block">
                    <input type="number" name="team_earnings" value="{$team.team_earnings}" lay-verify="team_earnings" mix=1 step="0.01" autocomplete="off" placeholder="请输入标题" class="layui-input iwidth">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">创建日期</label>
                <div class="layui-input-inline">
                    <input type="text" readonly  value="{$team.create_time}" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input " >
                </div>

            </div>

            <div class="layui-form-item" >
                <label class="layui-form-label">匹配类型</label>

                <div class="layui-input-block" >
                    <input type="radio" name="matching_type" value="1"  lay-filter="radio"  title="独立匹配" {if condition="$team.matching_type == 1"}checked{/if}>
                    <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>独立匹配</div></div>

                    <input type="radio"  name="matching_type" value="2"  lay-filter="radio"   title="综合匹配"{if condition="$team.matching_type == 2"}checked{/if}>
                    <div class="layui-unselect layui-form-radio" ><i class="layui-anim layui-icon"></i><div>综合匹配</div></div>

                </div>
            </div>
           <!-- <div class="layui-form-item" >
                &lt;!&ndash;筛选开始&ndash;&gt;
                <div class="layui-inline">
                    <label class="layui-form-label">搜索</label>
                    <div class="layui-input-inline">
                        <input type="text" name="search" id="searchuser" value="" lay-verify="" placeholder="请根据团队名称搜索" class="layui-input ">
                    </div>
                </div>

                <div class="layui-inline">
                    <button type="button" class="layui-btn" onclick="souTeam()" > <i class="layui-icon"></i> 搜 索</button>
                </div>
            </div>
-->

            <div class="layui-form-item" id="checkbox" {if condition="$team.matching_type == 1"}style="display:none"{/if}>
                <label class="layui-form-label">团队名称</label>

                <div class="layui-input-block" style=" padding:0px 0px 10px;box-sizing:border-box;width:1200px;overflow: auto;display: flex;flex-wrap: wrap;justify-content: flex-start">
                    <div style="width:200px">
                        <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary" title="全选">

                    </div>
                    {volist name="memberTeam" id="v"}
                        {if condition="in_array($v.id,$teamSet)"}
                        <div style="width:200px">
                            <input type="checkbox" name="team_set[]" class="checkboxs"   value="{$v.id}" lay-skin="primary" title="{$v.title}"   checked="">

                        </div>
                        {else/}
                        <div style="width:200px">
                            <input type="checkbox" name="team_set[]" class="checkboxs"   value="{$v.id}" lay-skin="primary" title="{$v.title}"  >

                        </div>
                        {/if}
                    {/volist}

                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="add">立即修改</button>
                </div>
            </div>
        </form>

    </div>
</div>

{include file="public/footer" /}

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate','wangEditor'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , wangEditor = layui.wangEditor
            , $ = layui.jquery;
        // 监听全选
        form.on('checkbox(checkall)', function (data) {
            console.log(data);
            if (data.elem.checked) {
                $('.checkboxs').prop('checked', true);
            } else {
                $('.checkboxs').prop('checked', false);
            }
            form.render('checkbox');
        });
        $(this).removeAttr("lay-key");//时间框一点就消失处理
        // 上架开始日期
        /*var insShelf = laydate.render({
            elem: '#create_time'
            , min: 0
            , trigger : 'click'//时间框一点就消失处理
            , calendar: true
            , type: 'datetime'
            , done: function (value, date) {
             /!*   //更新结束日期的最小日期
                insUnder.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });*!/

                //自动弹出结束日期的选择器
                //insUnder.config.elem[0].focus();
            }
        });*/
        form.on('radio(radio)', function(data){
            if(data.value == 1){
                //独立匹配
                document.querySelector("#checkbox").style.display='none';
            }else if(data.value == 2){
                //综合匹配
                document.querySelector("#checkbox").style.display='block';
            }

        });
        //自定义验证规则
        form.verify({
            question: function (value) {
                if (value == '') {
                    return '问题不能为空';
                }
            },
            answer: function (value) {
                if (value == '') {
                    return '答案不能为空';
                }
            }
            ,
            qtype: function (value) {
                if (value == '') {
                    return '请选择类型';
                }
            }
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交修改
        form.on('submit(add)', function (data) {
            let  postdata =data.field
            // postdata.answer=editor.txt.html()
            $.ajax({
                url: '/admin/team/write?active=ajax',
                type: 'post',
                dataType: 'json',
                data: postdata,
                success: function (res) {
                    if (res.status == true) {    // 获得frame索引
                        parent.layer.msg("操作成功!",
                            {
                                icon:1,
                                time: 1000
                            },
                            function () {
                            //重新加载父页面
                            parent.location.reload();
                        });
                        return;
                    } else{
                        layer.msg(res.msg,{icon:5,time:1000});
                    }
                },
                error: function () {
                    layer.msg("报错了");
                }
            });
            return false;
            /*layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })*/
        });


    });
    //查看用户信息
    function clickMember(memberCode){
        var index = layer.open({
            title:'领导人信息',
            type: 2,
            area: ['100%', '100%'],
            fixed: false, //不固定
            shade:0.5,
            shadeClose:true,
            content: '/admin/member/write?code='+memberCode,
        });
        return false;


    }
    function clickReplace(oldmemberCode){
        //默认prompt
        layer.prompt({
            formType: 0,
            phone: '',
            title: '请输入手机号'
        },function(phone, index){
            if (isNaN(phone)) {
                layer.msg("请输入手机号!",{ icon:5,
                    time: 1000});
                return;
            } else {
                $.ajax({
                    url: '/admin/team/member_so',
                    type: 'post',
                    dataType: 'json',
                    data: {phone:phone},
                    success: function (res) {
                        if (res.status == true) {
                            // 获得frame索引
                            var index = layer.open({
                                title:'玩家信息',
                                type: 2,
                                area: ['100%', '100%'],
                                fixed: false, //不固定
                                shade:0.5,
                                shadeClose:true,
                                content: "/admin/team/getMember?oldmemberCode='"+oldmemberCode+"'&teamId={$id}&phone="+phone,
                            });

                        }else{
                            layer.msg(res.msg,{ icon:5,
                                time: 1000});
                        }
                    },
                    error: function () {
                        layer.msg("报错了");
                    }
                });
            }
            return false;
        });
    }
    //搜索
   function souTeam(){
       var search = $("input[name='search']").val();
       $.ajax({
           url: "/admin/notice/create?type={$type}",
           type: 'post',
           async:true,
           data:{search:search},
           dataType: 'json',
           success: function (res) {
               if(res.status == true){
                   $(".showuser").html(res.param);
                   form.render()
               }else{
                   layer.msg(res.msg,{icon:5,time: 1000})
               }

           },
           error: function (res) {
               console.log(res);
           }
       });

   }
</script>
</body>
</html>